package idbuilder

import (
	"strconv"
	"sync/atomic"
	"time"
)

var ImageCntObjectIDCounter uint32

type ImageCntObjectIDType string

const (
	ImageCntObjectIDTypePerson          ImageCntObjectIDType = "01"
	ImageCntObjectIDTypeMotorVehicle    ImageCntObjectIDType = "02"
	ImageCntObjectIDTypeNonMotorVehicle ImageCntObjectIDType = "03"
	ImageCntObjectIDTypeThing           ImageCntObjectIDType = "04"
	ImageCntObjectIDTypeScene           ImageCntObjectIDType = "05"
	ImageCntObjectIDTypeFace            ImageCntObjectIDType = "06"
	ImageCntObjectIDTypeOther           ImageCntObjectIDType = "99"
)

// 视频图像信息基本对象统一标识编码规则语义
func GetImageCntObjectID(deviceID string, subType VideoSubType, ImageCntObjectIDType ImageCntObjectIDType) string {
	return GetImageObjectID(deviceID, subType) + string(ImageCntObjectIDType) + GetImageCntObjectIDCounter()
}

func GetImageCntObjectIDByTimeStr(timeStr, deviceID string, subType VideoSubType, ImageCntObjectIDType ImageCntObjectIDType) string {
	return GetImageObjectIDByTimeStr(GetNowTimeStr(), deviceID, subType) + string(ImageCntObjectIDType) + GetImageCntObjectIDCounter()
}

func GetNowTimeStr() string {
	return time.Now().Format("20060102150405")
}

func GetImageCntObjectIDCounter() string {
	atomic.AddUint32(&ImageCntObjectIDCounter, 1)
	n := "0000" + strconv.Itoa(int(ImageCntObjectIDCounter))
	return n[len(n)-5:]
}
